<script lang="ts" setup name="Logo">
import { storeToRefs } from "pinia";
import useSettingsStore from "@/store/modules/settings";
import useUserStore from "@/store/modules/user";

const userStore = useUserStore();
const { configData } = storeToRefs(userStore);
defineProps({
  showLogo: {
    type: Boolean,
    default: true,
  },
  showTitle: {
    type: Boolean,
    default: true,
  },
});

const settingsStore = useSettingsStore();

const title = ref(import.meta.env.VITE_APP_TITLE);

const to = computed(() => {
  const rtn: {
    name?: string;
  } = {};
  if (settingsStore.settings.home.enable) {
    rtn.name = "home";
  }
  return rtn;
});
</script>

<template>
  <router-link :to="to" class="title" :class="{ 'is-link': settingsStore.settings.home.enable }" :title="title">
    <img v-if="showLogo" src="@/assets/images/logo.png" class="logo" />
    <span v-if="showTitle">{{ title }}</span>
  </router-link>
</template>

<style lang="scss" scoped>
.title {
  position: fixed;
  z-index: 1000;
  top: 0;
  width: inherit;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--g-sidebar-logo-height);
  text-align: center;
  overflow: hidden;
  text-decoration: none;

  &.is-link {
    cursor: pointer;
  }

  .logo {
    // width: 30px;
    height: 30px;
    object-fit: contain;
    margin-right: 8px;

    & + span {
      margin-left: 10px;
    }
  }

  span {
    display: block;
    font-weight: bold;
    color: #000 !important;
    font-size: 20px !important;

    @include text-overflow;
  }
}
</style>
